<?php  if ( ! defined('BASEPATH')) exit('No direct script access allowed');
	class Admin_group_model extends CI_Model{
		
		function __construct()
		{
			parent::__construct();
			$this->table = 'admin_group';
                        $this->admin_table = 'admin';
		}
		
		
		function Get($id)
		{
			return $this->db->select('*')
			  ->from($this->table)
			  ->where('id' , $id)
			  ->get()
			  ->row_array();
		}
		
		
		public function GetAll($where)
	    {
			$this->db->select('*');
			$this->db->from($this->table);
			if($where){
			$this->db->where($where);
			}
			$this->db->order_by('sort asc , id asc');
			$query = $this->db->get();
			return $query->result_array();
	    }
		
		function group_select($selectid='')
		{
			$group = $this->db->select('*')
			  ->where('status' , '1')
			  ->from($this->table)
			  ->order_by('sort asc , id asc')
			  ->get()
			  ->result_array();
			  $groupoption = '';
			  foreach($group as $item){
				$selected = '';
				if($item['id']==$selectid){
				$selected = 'selected';
				}
			  $groupoption .='<option '.$selected.' value="'.$item['id'].'">'.$item['group_name'].'</option>';
			  
			  }
			  return $groupoption;
		}
		
		public function get_count($where){
		$this->db->select('*');
		$this->db->from($this->table);
		$this->db->where($where);
		$this->db->order_by("id", "desc");
		$query = $this->db->get();
		return $query->num_rows();
		}
		
		function insert($data)
		{
			$this->db->insert($this->table, $data);
			return $this->db->affected_rows();
		}
		
		function update($data,$id)
		{
			return $this->db->where('id',$id)->update($this->table, $data);
		}
		
		function delete($delid)
		{   	
                        $this->db->where('group_id',$delid);
			$this->db->delete($this->admin_table);
                        $result = $this->db->affected_rows();
                        
			$this->db->where('id',$delid);
			$this->db->delete($this->table);
			return $this->db->affected_rows();
		}
		
		
		
	}